//
//  PersonCenterVC.m
//  ZZLC
//
//  Created by 杨春至 on 2017/12/15.
//  Copyright © 2017年 ZhongZeng. All rights reserved.
//

#import "PersonCenterVC.h"
#import "PersonCenterTableViewCell.h"
#import "BorrowDetailThirdTableViewCell.h"
#import "ModifyAccoutSafetyVC.h"
#import "AuthenticationVC.h"

#import "ZZLSetingPWDVC.h"
@interface PersonCenterVC ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic)UITableView *tableView;
@end

@implementation PersonCenterVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"个人中心";
    [self.view addSubview:self.tableView];
    self.tableView.backgroundColor = COLORE_GLOBLE_BACKGOUNDCOLOR;
    // Do any additional setup after loading the view from its nib.
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    switch (section) {
        case 0:
        case 2:
        {
            return 1;
            
        }
            break;
            
        default:
        {
            return 2;
        }
            break;
    }
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
       K_WS(weakSelf);
    if (indexPath.section == 2) {
        NSArray *nibs = [[NSBundle mainBundle]loadNibNamed:@"BorrowDetailThirdTableViewCell" owner:self options:nil];
        BorrowDetailThirdTableViewCell *cell = [nibs firstObject];
        [cell.stateBTN setTitle:@"安全退出" forState:UIControlStateNormal];
        [cell.stateBTN bk_whenTapped:^{
            [UserModel clearData];
            [[NSNotificationCenter defaultCenter] postNotificationName:K_NOTIFICATION_ISLOGIN_SUCCESS object:nil];
            [weakSelf.navigationController popViewControllerAnimated:YES];
        }];
        return cell;
        
    }
    else{
        NSArray *nibs = [[NSBundle mainBundle]loadNibNamed:@"PersonCenterTableViewCell" owner:self options:nil];
        PersonCenterTableViewCell *cell = [nibs firstObject];
        switch (indexPath.section) {
            case 0:
            {
                cell.leftLabel.text=@"实名认证";
                if (_isverified) {
                       cell.rightLabel.text=@"已认证";
                }else{
                        cell.rightLabel.text=@"未认证";
                }

            }
                break;
                
            default:
            {
                switch (indexPath.row) {
                    case 0:
                    {
                    cell.leftLabel.text=@"修改登录密码";
                    cell.rightLabel.text=@"";
                    }
                        break;
                        
                    default:
                    {
                        cell.leftLabel.text=self.isPayPwd?@"修改交易密码":@"设置交易密码";
                    cell.rightLabel.text=@"";
                    }
                        break;
                }
            }
                break;
        }
        return cell;
    }
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if (section == 1) {
        UIView *view =[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 10)];
        view.backgroundColor = COLORE_GLOBLE_BACKGOUNDCOLOR;
        return view;
    }
    else{
        return nil;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 1) {
        return 10.0f;
    }
    else{
        return 0;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch (indexPath.section) {
        case 2:
            return 103;
            break;
            
        default:
            return 56;
            break;
    }
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch (indexPath.section) {
        case 0:
            {
            
                AuthenticationVC *aVC = [[AuthenticationVC alloc]init];
                aVC.hasAuthent = _isverified;
                [self.navigationController pushViewController:aVC animated:YES];
            }
            break;
        case 1:
        {
            PersonCenterTableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
            if ([cell.leftLabel.text isEqualToString:@"设置交易密码"]) {
                ZZLSetingPWDVC * settngPwdVC = [[ZZLSetingPWDVC alloc]initWithNibName:@"ZZLSetingPWDVC" bundle:nil];
                settngPwdVC.phoneStr = [UserModel userName];
                settngPwdVC.fromWhere = TRADEPWDTVC;
                [self.navigationController pushViewController:settngPwdVC animated:YES];
            }
            else
            {
                ModifyAccoutSafetyVC *vc = [[ModifyAccoutSafetyVC alloc]initWithNibName:@"ModifyAccoutSafetyVC" bundle:nil];
                vc.titleStr = cell.leftLabel.text;
                if ([vc.titleStr isEqualToString:@"修改登录密码"]) {
                    vc.typeStr = @"0";
                }
                else
                {
                    vc.typeStr = @"1";
                }
                [self.navigationController pushViewController:vc animated:YES];
            }
        }
            break;
        default:
        {
          
        }
            break;
    }
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}
- (UITableView *)tableView
{
    if (!_tableView) {
        self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) style:UITableViewStylePlain];
        self.tableView.delegate = self;
        self.tableView.dataSource = self;
        self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    return _tableView;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
